package com.game.centerserver.controller;

import com.game.centerserver.common.Result;
import com.game.centerserver.infrastructure.entity.Product;
import com.game.centerserver.infrastructure.service.ProductService;
import com.game.centerserver.service.ProductServiceService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: tian
 * @Date: 2024/11/19/16:09
 * @Description:
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;

    @GetMapping("/queryProductById")
    public Result<Product> queryProductById(Integer id){
        Product product = productService.queryById(id);
        return Result.ok("查询成功",product);
    }

    @PostMapping("/addProduct")
    public Result<Product> addProduct(Product product){
        Product insert = productService.insert(product);
        if (insert != null){
            return Result.ok("添加产品信息成功", product);
        }else {
            return Result.fail("添加产品信息失败");
        }
    }

    @DeleteMapping("/deleteProductById")
    public Result deleteProductById(Integer productId){
        boolean delete = productService.deleteById(productId);
        if (delete){
            return Result.ok("删除产品信息成功");
        }else {
            return Result.fail("删除产品信息失败");
        }
    }

    @PutMapping("/updateProduct")
    public Result updateProduct(Product product){
        boolean update = productService.update(product);
        if (update){
            return Result.ok("修改产品信息成功");
        }else {
            return Result.fail("修改产品信息失败");
        }
    }
}
